#include "../mqserver/Binding.hpp"
#include <gtest/gtest.h>
#include <iostream>
#include <unordered_map>
using namespace std;
mq::BindingManager::BindingManagerPtr bmp;
class BindingTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        bmp = make_shared<mq::BindingManager>("./data/test.db");
        cout << "测试环境初始化" << endl;
    }
    virtual void TearDown() override
    {
        bmp->clear();
        cout << "测试环境清理" << endl;
    }
};
// TEST(binding, insert_test)
// {
//     bmp->bind("exchange1", "queue1", "music", true);
//     bmp->bind("exchange1", "queue2", "sport", true);
//     bmp->bind("exchange1", "queue3", "gossip", true);
//     bmp->bind("exchange2", "queue1", "music", true);
//     bmp->bind("exchange2", "queue2", "sport", true);
//     bmp->bind("exchange2", "queue3", "study", true);
//     ASSERT_EQ(bmp->size(), 6);
// }

// TEST(binding, select_test)
// {
//     auto um = bmp->getExchangeBindings("exchange1");
//     ASSERT_EQ(um.size(), 3);
//     ASSERT_EQ(um["queue1"]->_binding_key, string("music"));
//     ASSERT_EQ(um["queue2"]->_binding_key, string("sport"));
//     ASSERT_EQ(um["queue3"]->_binding_key, string("gossip"));

//     auto it = bmp->getBinding("exchange2", "queue3");
//     ASSERT_NE(it.get(), nullptr);
//     ASSERT_EQ(it->_exchange_name, string("exchange2"));
//     ASSERT_EQ(it->_msgqueue_name, string("queue3"));
//     ASSERT_EQ(it->_binding_key, string("study"));
// }
// TEST(binding, delete_test)
// {
//     bmp->removeExchangeBindings("exchange1");
//     ASSERT_EQ(bmp->exists("exchange1", "queue1"), false);
//     ASSERT_EQ(bmp->exists("exchange1", "queue2"), false);
//     ASSERT_EQ(bmp->exists("exchange1", "queue3"), false);

//     bmp->removeMsgQueueBindings("queue2");
//     ASSERT_EQ(bmp->exists("exchange2", "queue1"), true);
//     ASSERT_EQ(bmp->exists("exchange2", "queue2"), false);
//     ASSERT_EQ(bmp->exists("exchange2", "queue3"), true);
// }
TEST(binding, recovery_test)
{
    ASSERT_EQ(bmp->exists("exchange1", "queue1"), false);
    ASSERT_EQ(bmp->exists("exchange1", "queue2"), false);
    ASSERT_EQ(bmp->exists("exchange1", "queue3"), false);
    ASSERT_EQ(bmp->exists("exchange2", "queue1"), true);
    ASSERT_EQ(bmp->exists("exchange2", "queue2"), false);
    ASSERT_EQ(bmp->exists("exchange2", "queue3"), true);
}
int main(int argc, char *argv[])
{
    testing::AddGlobalTestEnvironment(new BindingTest);
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}